home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / OrgPlus 7 SBE / ORGPL.CAB / indexPage.js < prev    next >
Encoding:
Text File  |  2007-05-15  |  4.6 KB  |  191 lines

  1. /**********************************************************
  2. *                                                         *
  3. * (C) Copyright 2002 - 2004,  Human Concepts (tm)         *
  4. *                                                         *
  5. ***********************************************************
  6. * File name: indexPage.js                                 *
  7. * Author: Andrey Ponomarev                                *
  8. **********************************************************/
  9.  
  10.   window.onload = doInit
  11.   window.onresize = onResize
  12.  
  13.  
  14.   var bCapture = false
  15.  
  16.   function onResize()
  17.   { 
  18.     var nWidth = document.body.clientWidth
  19.  
  20.     if( typeof(PersonList) == "object" )
  21.       PersonList.style.width = nWidth + 3
  22.   }
  23.  
  24.   function doInit()
  25.   {
  26.     CreateControls()
  27.     var obj = parent.hcMain
  28.     if ( typeof (obj) == "object" && typeof (obj.onNavigatePageInit) != "undefined" )
  29.       obj.onNavigatePageInit()
  30.   }
  31.  
  32.   var idxArray = null;
  33.   var idxCount = 0;
  34.  
  35.   function fillIndexArray(person)
  36.   {
  37.     AddToArray( person );
  38.     var spanObjs = person.children.tags("span");
  39.  
  40.     for(var j = 0; j < spanObjs.length; ++j)
  41.       fillIndexArray(spanObjs[j]);
  42.   }
  43.   
  44.   function AddToArray( p_oPerson )
  45.   {
  46.     var paramObjs = p_oPerson.getElementsByTagName("param");
  47.     var obj = null;
  48.     for (i = 0; i < paramObjs.length; ++i)
  49.     {      
  50.       var o = paramObjs[i];
  51.       if (o.id == GetPrimaryFld())  
  52.       {
  53.         obj = o;
  54.         break;
  55.       }
  56.     }
  57.     
  58.     if( obj != null )
  59.     {
  60.       idxArray[idxCount] = new Object();
  61.       idxArray[idxCount].Text = obj.name;
  62.       idxArray[idxCount].url = p_oPerson.src;
  63.       idxCount++;
  64.     }
  65.   }
  66.   
  67.   function sortFunct( a, b )
  68.   {
  69.     return IsAsc() ? a.Text < b.Text : b.Text < a.Text;
  70.   }
  71.  
  72.   var bFilled = 0;
  73.  
  74.   function fillPage(group)
  75.   {
  76.     if( typeof( parent.hcPersons ) != "object" )
  77.     {
  78.       parent.hcMain.focus();
  79.       return;
  80.     }
  81.     
  82.     if( bFilled ) return;
  83.  
  84.     var fieldsObj = parent.hcMain.getFieldsObj()
  85.     if(fieldsObj == null) return
  86.  
  87.     if( ProcessHeaders(fieldsObj) == -1 )
  88.       return; //Error!
  89.         
  90. //    var id = group.id
  91. //    var objPerson = parent.hcMain.findPersonNode(id,null)
  92. //    if(objPerson == null)  return
  93.     var objPerson = parent.hcMain.getPersonsObj().children[0];
  94.     idxArray = new Array()
  95.     idxCount = 0
  96.     
  97.     fillIndexArray(objPerson);
  98.     var r = idxArray.sort( sortFunct );
  99.     
  100.     for (j = 0; j < idxArray.length; j++)
  101.       AddListItem( idxArray[j].Text, idxArray[j].url );
  102.  
  103.     parent.hcMain.focus();
  104.     bFilled = 1;
  105.   }
  106.  
  107.   function ProcessHeaders(objHeaders)
  108.   {
  109.     if( typeof(objHeaders) != "object" )
  110.       return -1;
  111.  
  112.     var strTitle = "";
  113.     var paramObjs = objHeaders.getElementsByTagName("param");
  114.  
  115.     for (var j = 0; j < paramObjs.length; j++)
  116.     {
  117.       var obj = paramObjs[j];
  118.       
  119.       if( obj.name != null && obj.id == GetPrimaryFld() )
  120.       {
  121.         strTitle = obj.name;
  122.         if( typeof( TitleText ) == "undefined" || TitleText == null )
  123.           continue;
  124.         TitleText.innerText = "Persons (" + strTitle + "):"; //Loc
  125.         
  126.         return obj.id;
  127.       }
  128.     }
  129.  
  130.     return -1;
  131.   }
  132.  
  133.   function CreateControls()
  134.   {
  135.     if ( typeof(TitleText) == 'undefined' )
  136.     {
  137.       var elem = document.createElement("span");
  138.       elem.id = "TitleText";
  139.       document.body.appendChild(elem);
  140.     }
  141.     
  142.     if( typeof( PersonList ) == 'undefined' )
  143.     {
  144.       var elem = document.createElement("<table>");
  145.       elem.id = 'PersonList';
  146.       var oRow = elem.insertRow( 0 );
  147.       oRow.insertCell(0);
  148.       
  149.       document.body.appendChild( elem );
  150.     }
  151.     onResize()
  152.   }
  153.  
  154.   function AddListItem( str, url )           
  155.   {
  156.     if (typeof(str) != "undefined" && str != "")
  157.     {
  158.       var u = document.createElement( '<ul></ul>' );
  159.       var elem = document.createElement( '<li></li>' );
  160.       elem.innerHTML = '<span class="indexItem" _url="' + url + '" onclick="OnPersonDblClicked();">' + str + '</a>';
  161.       
  162.       PersonList.rows[0].cells[0].appendChild(u);
  163.       PersonList.rows[0].cells[0].childNodes[0].appendChild(elem);
  164.     }
  165.   }
  166.  
  167.   function OnPersonDblClicked()
  168.   {
  169.     var obj = event.srcElement;
  170.     ShowBox( obj._url );
  171.   }
  172.  
  173.  function ShowBox(strSrc)
  174.  { 
  175.     var hcMain = parent.hcMain
  176.     var s = strSrc.split("#")
  177.     if(s.length!=2) return;
  178.  
  179.     if(s[0].length!=0)
  180.     {
  181.       if( hcMain.location.pathname.indexOf(s[0]) != -1 )
  182.         hcMain.navigateBox(s[1]);
  183.       else 
  184.         hcMain.location.replace(strSrc)
  185.     }
  186.     else
  187.     {
  188.       hcMain.navigateBox(s[1]);
  189.     }
  190.  } 
  191.